<?php

namespace UU\Suite\Kernel\Traits;


use Psr\SimpleCache\CacheInterface;


/**
 * Trait InteractsWithCache.
 *
 * @author overtrue <i@overtrue.me>
 */
trait InteractsWithCache
{
    protected ?CacheInterface $cache = null;

    public function setCache(CacheInterface $cache): self
    {
        $this->cache = $cache;

        return $this;
    }

    public function getCache(): CacheInterface
    {
        if (!$this->cache) {
            $this->cache = make(CacheInterface::class);
        }

        return $this->cache;
    }
}